import { useState, useImperativeHandle, forwardRef } from 'react';

//演示子父级函数调用
let Hooks2 = (props, ref)=>{
	const [count1, setCount1] = useState(0);
	const [count2, setCount2] = useState(9);
	//在父级中调用 getInfo
	useImperativeHandle(ref, () => ({
        getInfo: ()=>{
            //需要处理的数据
            console.log('from parent')
        }
    }))
	return (
		<div>
			<button onClick={() => {setCount1(count1 + 1);props.add1()}}>按钮1:调用父级:{count1}</button>
			<button onClick={() =>{ setCount2(count2 + 1);}}>按钮2:{count2}</button>
		</div>
	);
}

Hooks2 = forwardRef(Hooks2);
export default Hooks2 